clear

log using "C:\Users\user\OneDrive - konkuk.ac.kr\research\my papers\new papers\baseball\baseball.smcl", replace

import excel "C:\Users\user\OneDrive - konkuk.ac.kr\research\my papers\new papers\baseball\data.xlsx", sheet("Sheet1") firstrow


drop if season==2020
xtset id year

gen winp=100*win/(win+loss)
gen logsalary=log(salary)

gen one_year=0
replace one_year=contract1 if contract1!=. & year1==1
replace one_year=one_year+contract2 if contract2!=. & year2==1
replace one_year=one_year+contract3 if contract3!=. & year3==1
replace one_year=one_year+contract4 if contract4!=. & year4==1
replace one_year=one_year+contract5 if contract5!=. & year5==1
replace one_year=one_year+contract6 if contract6!=. & year6==1
replace one_year=one_year+contract7 if contract7!=. & year7==1
replace one_year=one_year+contract8 if contract8!=. & year8==1
replace one_year=one_year+contract9 if contract9!=. & year9==1
replace one_year=one_year+contract10 if contract10!=. & year10==1
replace one_year=one_year+contract11 if contract11!=. & year11==1

gen first_year=0
replace first_year=contract1/year1 if contract1!=. & year1>1
replace first_year=first_year+contract2/year2 if contract2!=. & year2>1
replace first_year=first_year+contract3/year3 if contract3!=. & year3>1
replace first_year=first_year+contract4/year4 if contract4!=. & year4>1
replace first_year=first_year+contract5/year5 if contract5!=. & year5>1
replace first_year=first_year+contract6/year6 if contract6!=. & year6>1
replace first_year=first_year+contract7/year7 if contract7!=. & year7>1
replace first_year=first_year+contract8/year8 if contract8!=. & year8>1
replace first_year=first_year+contract9/year9 if contract9!=. & year9>1
replace first_year=first_year+contract10/year10 if contract10!=. & year10>1
replace first_year=first_year+contract11/year11 if contract11!=. & year11>1

gen second_year=0
replace second_year=l.contract1/l.year1 if l.contract1!=. & l.year1>=2
replace second_year=l.contract2/l.year2 if l.contract2!=. & l.year2>=2
replace second_year=l.contract3/l.year3 if l.contract3!=. & l.year3>=2
replace second_year=l.contract4/l.year4 if l.contract4!=. & l.year4>=2
replace second_year=l.contract5/l.year5 if l.contract5!=. & l.year5>=2
replace second_year=l.contract6/l.year6 if l.contract6!=. & l.year6>=2
replace second_year=l.contract7/l.year7 if l.contract7!=. & l.year7>=2
replace second_year=l.contract8/l.year8 if l.contract8!=. & l.year8>=2
replace second_year=l.contract9/l.year9 if l.contract9!=. & l.year9>=2
replace second_year=l.contract10/l.year10 if l.contract10!=. & l.year10>=2
replace second_year=l.contract11/l.year11 if l.contract11!=. & l.year11>=2

gen third_year=0
replace third_year=l2.contract1/l2.year1 if l2.contract1!=. & l2.year1>=3
replace third_year=l2.contract2/l2.year2 if l2.contract2!=. & l2.year2>=3
replace third_year=l2.contract3/l2.year3 if l2.contract3!=. & l2.year3>=3
replace third_year=l2.contract4/l2.year4 if l2.contract4!=. & l2.year4>=3
replace third_year=l2.contract5/l2.year5 if l2.contract5!=. & l2.year5>=3
replace third_year=l2.contract6/l2.year6 if l2.contract6!=. & l2.year6>=3
replace third_year=l2.contract7/l2.year7 if l2.contract7!=. & l2.year7>=3
replace third_year=l2.contract8/l2.year8 if l2.contract8!=. & l2.year8>=3
replace third_year=l2.contract9/l2.year9 if l2.contract9!=. & l2.year9>=3
replace third_year=l2.contract10/l2.year10 if l2.contract10!=. & l2.year10>=3
replace third_year=l2.contract11/l2.year11 if l2.contract11!=. & l2.year11>=3

gen fourth_year=0
replace fourth_year=l3.contract1/l3.year1 if l3.contract1!=. & l3.year1>=4
replace fourth_year=l3.contract2/l3.year2 if l3.contract2!=. & l3.year2>=4
replace fourth_year=l3.contract3/l3.year3 if l3.contract3!=. & l3.year3>=4
replace fourth_year=l3.contract4/l3.year4 if l3.contract4!=. & l3.year4>=4
replace fourth_year=l3.contract5/l3.year5 if l3.contract5!=. & l3.year5>=4
replace fourth_year=l3.contract6/l3.year6 if l3.contract6!=. & l3.year6>=4
replace fourth_year=l3.contract7/l3.year7 if l3.contract7!=. & l3.year7>=4
replace fourth_year=l3.contract8/l3.year8 if l3.contract8!=. & l3.year8>=4
replace fourth_year=l3.contract9/l3.year9 if l3.contract9!=. & l3.year9>=4
replace fourth_year=l3.contract10/l3.year10 if l3.contract10!=. & l3.year10>=4
replace fourth_year=l3.contract11/l3.year11 if l3.contract11!=. & l3.year11>=4

gen fifth_year=0
replace fifth_year=l4.contract1/l4.year1 if l4.contract1!=. & l4.year1>=5
replace fifth_year=l4.contract2/l4.year2 if l4.contract2!=. & l4.year2>=5
replace fifth_year=l4.contract3/l4.year3 if l4.contract3!=. & l4.year3>=5
replace fifth_year=l4.contract4/l4.year4 if l4.contract4!=. & l4.year4>=5
replace fifth_year=l4.contract5/l4.year5 if l4.contract5!=. & l4.year5>=5
replace fifth_year=l4.contract6/l4.year6 if l4.contract6!=. & l4.year6>=5
replace fifth_year=l4.contract7/l4.year7 if l4.contract7!=. & l4.year7>=5
replace fifth_year=l4.contract8/l4.year8 if l4.contract8!=. & l4.year8>=5
replace fifth_year=l4.contract9/l4.year9 if l4.contract9!=. & l4.year9>=5
replace fifth_year=l4.contract10/l4.year10 if l4.contract10!=. & l4.year10>=5
replace fifth_year=l4.contract11/l4.year11 if l4.contract11!=. & l4.year11>=5

gen sixth_year=0
replace sixth_year=l5.contract1/l5.year1 if l5.contract1!=. & l5.year1>=6
replace sixth_year=l5.contract2/l5.year2 if l5.contract2!=. & l5.year2>=6
replace sixth_year=l5.contract3/l5.year3 if l5.contract3!=. & l5.year3>=6
replace sixth_year=l5.contract4/l5.year4 if l5.contract4!=. & l5.year4>=6
replace sixth_year=l5.contract5/l5.year5 if l5.contract5!=. & l5.year5>=6
replace sixth_year=l5.contract6/l5.year6 if l5.contract6!=. & l5.year6>=6
replace sixth_year=l5.contract7/l5.year7 if l5.contract7!=. & l5.year7>=6
replace sixth_year=l5.contract8/l5.year8 if l5.contract8!=. & l5.year8>=6
replace sixth_year=l5.contract9/l5.year9 if l5.contract9!=. & l5.year9>=6
replace sixth_year=l5.contract10/l5.year10 if l5.contract10!=. & l5.year10>=6
replace sixth_year=l5.contract11/l5.year11 if l5.contract11!=. & l5.year11>=6

gen seventh_year=0
replace seventh_year=l6.contract1/l6.year1 if l6.contract1!=. & l6.year1>=7
replace seventh_year=l6.contract2/l6.year2 if l6.contract2!=. & l6.year2>=7
replace seventh_year=l6.contract3/l6.year3 if l6.contract3!=. & l6.year3>=7
replace seventh_year=l6.contract4/l6.year4 if l6.contract4!=. & l6.year4>=7
replace seventh_year=l6.contract5/l6.year5 if l6.contract5!=. & l6.year5>=7
replace seventh_year=l6.contract6/l6.year6 if l6.contract6!=. & l6.year6>=7
replace seventh_year=l6.contract7/l6.year7 if l6.contract7!=. & l6.year7>=7
replace seventh_year=l6.contract8/l6.year8 if l6.contract8!=. & l6.year8>=7
replace seventh_year=l6.contract9/l6.year9 if l6.contract9!=. & l6.year9>=7
replace seventh_year=l6.contract10/l6.year10 if l6.contract10!=. & l6.year10>=7
replace seventh_year=l6.contract11/l6.year11 if l6.contract11!=. & l6.year11>=7

gen eighth_year=0
replace eighth_year=l7.contract1/l7.year1 if l7.contract1!=. & l7.year1>=8
replace eighth_year=l7.contract2/l7.year2 if l7.contract2!=. & l7.year2>=8
replace eighth_year=l7.contract3/l7.year3 if l7.contract3!=. & l7.year3>=8
replace eighth_year=l7.contract4/l7.year4 if l7.contract4!=. & l7.year4>=8
replace eighth_year=l7.contract5/l7.year5 if l7.contract5!=. & l7.year5>=8
replace eighth_year=l7.contract6/l7.year6 if l7.contract6!=. & l7.year6>=8
replace eighth_year=l7.contract7/l7.year7 if l7.contract7!=. & l7.year7>=8
replace eighth_year=l7.contract8/l7.year8 if l7.contract8!=. & l7.year8>=8
replace eighth_year=l7.contract9/l7.year9 if l7.contract9!=. & l7.year9>=8
replace eighth_year=l7.contract10/l7.year10 if l7.contract10!=. & l7.year10>=8
replace eighth_year=l7.contract11/l7.year11 if l7.contract11!=. & l7.year11>=8

gen nineth_year=0
replace nineth_year=l8.contract1/l8.year1 if l8.contract1!=. & l8.year1>=9
replace nineth_year=l8.contract2/l8.year2 if l8.contract2!=. & l8.year2>=9
replace nineth_year=l8.contract3/l8.year3 if l8.contract3!=. & l8.year3>=9
replace nineth_year=l8.contract4/l8.year4 if l8.contract4!=. & l8.year4>=9
replace nineth_year=l8.contract5/l8.year5 if l8.contract5!=. & l8.year5>=9
replace nineth_year=l8.contract6/l8.year6 if l8.contract6!=. & l8.year6>=9
replace nineth_year=l8.contract7/l8.year7 if l8.contract7!=. & l8.year7>=9
replace nineth_year=l8.contract8/l8.year8 if l8.contract8!=. & l8.year8>=9
replace nineth_year=l8.contract9/l8.year9 if l8.contract9!=. & l8.year9>=9
replace nineth_year=l8.contract10/l8.year10 if l8.contract10!=. & l8.year10>=9
replace nineth_year=l8.contract11/l8.year11 if l8.contract11!=. & l8.year11>=9

gen tenth_year=0
replace tenth_year=l9.contract1/l9.year1 if l9.contract1!=. & l9.year1>=10
replace tenth_year=l9.contract2/l9.year2 if l9.contract2!=. & l9.year2>=10
replace tenth_year=l9.contract3/l9.year3 if l9.contract3!=. & l9.year3>=10
replace tenth_year=l9.contract4/l9.year4 if l9.contract4!=. & l9.year4>=10
replace tenth_year=l9.contract5/l9.year5 if l9.contract5!=. & l9.year5>=10
replace tenth_year=l9.contract6/l9.year6 if l9.contract6!=. & l9.year6>=10
replace tenth_year=l9.contract7/l9.year7 if l9.contract7!=. & l9.year7>=10
replace tenth_year=l9.contract8/l9.year8 if l9.contract8!=. & l9.year8>=10
replace tenth_year=l9.contract9/l9.year9 if l9.contract9!=. & l9.year9>=10
replace tenth_year=l9.contract10/l9.year10 if l9.contract10!=. & l9.year10>=10
replace tenth_year=l9.contract11/l9.year11 if l9.contract11!=. & l9.year11>=10

gen eleventh_year=0
replace eleventh_year=l10.contract1/l10.year1 if l10.contract1!=. & l10.year1>=11
replace eleventh_year=l10.contract2/l10.year2 if l10.contract2!=. & l10.year2>=11
replace eleventh_year=l10.contract3/l10.year3 if l10.contract3!=. & l10.year3>=11
replace eleventh_year=l10.contract4/l10.year4 if l10.contract4!=. & l10.year4>=11
replace eleventh_year=l10.contract5/l10.year5 if l10.contract5!=. & l10.year5>=11
replace eleventh_year=l10.contract6/l10.year6 if l10.contract6!=. & l10.year6>=11
replace eleventh_year=l10.contract7/l10.year7 if l10.contract7!=. & l10.year7>=11
replace eleventh_year=l10.contract8/l10.year8 if l10.contract8!=. & l10.year8>=11
replace eleventh_year=l10.contract9/l10.year9 if l10.contract9!=. & l10.year9>=11
replace eleventh_year=l10.contract10/l10.year10 if l10.contract10!=. & l10.year10>=11
replace eleventh_year=l10.contract11/l10.year11 if l10.contract11!=. & l10.year11>=11


gen share_oneyear=100*one_year/salary
gen share_firstyear=100*first_year/salary
gen share_secondyear=100*second_year/salary
gen share_thirdyear=100*third_year/salary
gen share_fourthyear=100*fourth_year/salary
gen share_fifthyear=100*fifth_year/salary
gen share_sixthyear=100*sixth_year/salary
gen share_seventhyear=100*seventh_year/salary
gen share_eighthyear=100*eighth_year/salary
gen share_ninethyear=100*nineth_year/salary
gen share_tenthyear=100*tenth_year/salary
gen share_eleventhyear=100*eleventh_year/salary
gen share_fifthorabove=share_fifthyear+share_sixthyear+share_seventhyear+share_eighthyear+share_ninethyear+share_tenthyear

sum winp salary share_oneyear share_firstyear share_secondyear share_thirdyear share_fourthyear share_fifthorabove if season>=2010

reg winp logsalary share_oneyear share_firstyear share_secondyear share_thirdyear share_fourthyear share_fifthorabove if season>=2010, vce(cluster id)
xtreg winp logsalary share_oneyear share_firstyear share_secondyear share_thirdyear share_fourthyear share_fifthorabove if season>=2010, fe
xtreg winp logsalary share_oneyear share_firstyear share_secondyear share_thirdyear share_fourthyear share_fifthorabove if season>=2010, re


xtreg postseason logsalary share_oneyear share_firstyear share_secondyear share_thirdyear share_fourthyear share_fifthorabove if season>=2010, fe
logit postseason logsalary share_oneyear share_firstyear share_secondyear share_thirdyear share_fourthyear share_fifthorabove if season>=2010, vce(cluster id)
xtlogit postseason logsalary share_oneyear share_firstyear share_secondyear share_thirdyear share_fourthyear share_fifthorabove if season>=2010, fe
xtlogit postseason logsalary share_oneyear share_firstyear share_secondyear share_thirdyear share_fourthyear share_fifthorabove if season>=2010, re







log close
